*global model "C:\\Users\\venator\\Documents\\GitHub\\mig_fam\\Model"
//simulated data
import delimited "$model/simulated_data/simulated_data_base_combined.csv", clear
//import delimited "$model/simulated_data/simulated_data_base.csv", clear
ren v1 uniqid
ren v2 year
ren v3 mu
ren v4 e
ren v5 m
ren v6 p
ren v7 l
ren v8 age
ren v9 x
ren v10 ac
ren v11 f
ren v12 lp_type
ren v13 h
ren v14 wage
ren v15 l_prime
ren v16 sim
//drop if e==2 & age<4

//likelihood of moving to/from home, broken down by fertilty type
gen mig = (l_prime<11)
replace mig = . if l_prime == 99
gen home = (l == 1)
gen home_mig = (l_prime == 1)

preserve
import delimited "$model/utilities/div_chars.csv", clear
keep v1 v3
ren v1 l_prime_div
ren v3 lp_pop 
tempfile pops
save `pops'
restore

//mover statistics: education, amrital status, kid, age, destination state population
gen married = (m>1)
replace e = e-1
gen kid = (ac>1)
gen l_prime_div = .
replace l_prime_div = lp if mig & l_prime == 1 //parent destination
replace l_prime_div = l_prime - 1 if l_prime > 1 & l_prime< 11
merge m:1 l_prime_div using `pops', keep(1 3) nogen


preserve
import delimited  "$model/estimates_1.csv",clear
qui summ v1
local a1 = `r(mean)'
qui summ v5
local a5 =`r(mean)'
qui summ v19
local g0 =`r(mean)'
qui summ v20
local g1 =`r(mean)'
qui summ v21
local g2 =`r(mean)'
qui summ v22
local g3 =`r(mean)'
qui summ v23
local g4 =`r(mean)'
qui summ v24
local g5 =`r(mean)'

restore

g movingcost = 2080 * (kid/`a5' + (1-kid)/`a1')* (`g0' + `g1'*e + `g2'*kid+ `g3'*married + `g4'*lp_pop + `g5'*age)

su movingcost




//exit

//point of comparison: average lifetime consumption for non-movers by location


use "$temp/simulated_data_baseline_combined", clear
ren v1 uniqid
ren v2 year
ren v3 mu
ren v4 e
ren v5 m
ren v6 p
ren v7 l
ren v8 age
ren v9 x
ren v10 ac
ren v11 f
ren v12 lp_type
ren v13 h
ren v14 wage
ren v15 l_prime
ren v16 sim
ren v17 age_int
ren v21 tau
ren v22 util
//cap gen v23 = 0
ren v23 util_start
ren v25 race
replace util_start = util_start/41

//drop if age_int<25

ren util util_expost
ren util_start util

//drop if age_int>55 //truncate life cycle

gen parent = (l == 1)
gen mig = (l_prime<11)
gen mig_parent = (l_prime == 1) //move to parent location
gen mig_away = (mig & l==1) //move away 
gen mig_else = (mig & l_prime!=1 & l!=1)
gen temp = (ac>1 & m==1) //single parent
bys uniqid sim: egen singlepar = max(temp) //dummy for ever being a single parent
drop temp

gen temp = mig
bys uniqid sim: egen mig_ever = max(temp)
drop temp

replace l = l - 1
replace l = lp_type if l == 0

gen coli = 0
replace coli = 1.276 if l == 1
replace coli = 1.212 if l == 2
replace coli = 1.017 if l == 3
replace coli = 1.002 if l == 4
replace coli = 1.052 if l == 5
replace coli = 0.970 if l == 6
replace coli = 0.999 if l == 7
replace coli = 1.064 if l == 8
replace coli = 1.279 if l == 9	


replace wage = wage/coli //now a real wage!
replace wage = wage * 2.08 //reporting real wages in thousands of dollars now, since initially normalized by 2k
replace util = util * 2.08 //same thing for utility
replace util_expost = util_expost * 2.08 //same thing for utility


reg wage i.mu i.e i.race c.x##c.x ib1.ac ib4.l if h == 1 

regsave 1.l 2.l 3.l 4b.l 5.l 6.l 7.l 8.l 9.l using "$temp/div_wage_estimates", replace

use "$temp/div_wage_estimates", clear
gen div = _n
keep div coef
ren coef real_wage
tempfile etas
save `etas'

import delimited "$dir/Model/utilities/div_chars.csv", clear
ren v1 div 
ren v2 eta_s 
ren v4 kappa 
ren v5 delta
keep div eta_s kappa delta
merge 1:1 div using `etas', keep(match) nogen
order div kappa delta eta real_wage
texsave using "$output/Table_A7", replace




exit


reg wage i.mu i.e i.race c.x##c.x ib1.ac ib4.l if h == 1 & race == 1



reg wage i.mu i.e i.race c.x##c.x ib1.ac ib4.l if h == 1 & race == 2











*/
//end of dofile


